package com.csdemos.algs.greedy;

import java.util.LinkedList;

public class ActivitySelector {

    public static LinkedList<Integer> recursive(int [] s, int [] f, int i, int n) {
        
        int m = i+1;
        while (m < n && s[m] < f[i]) {
            m++;
        }
        if (m < n) {
            LinkedList<Integer> tmp = recursive(s, f, m, n);
            tmp.add(m);
            return tmp;
        } else {
            return new LinkedList<Integer>();
        }
        
        
    }
    
    public static LinkedList<Integer> iterative(int [] s, int [] f) {
        
        LinkedList<Integer> result = new LinkedList<Integer>();
        int n = s.length;
        result.add(0);
        int i = 0;
        for (int m = 1; m < n; m++) {
            if (s[m] >= f[i]) {
                result.add(m);
                i = m;
            }
        }
        return result;
    }
    
}
